package com.chen.q4;

import com.chen.q4.initial.NettyHttpServer;

import java.util.Arrays;
import java.util.List;

/**
 * 整合CloseableHttpAsyncClient
 * @author Charles
 */
public class NettyServerApplication {
    final static String GATEWAY_NAME = "NIO_Gateway";
    final static String VERSION = "v3.0.0 实现简单路由功能";

    public static void main(String[] args) {
        int proxyPort = 8088;
        String proxiedServer = "http://127.0.0.1:8801;http://127.0.0.1:8802;http://127.0.0.1:8803";

        if (args !=null ){
            if (args.length > 0){
                try {
                    proxyPort = Integer.valueOf(args[0]);
                } catch (NumberFormatException e) {
                    //端口号默认8088
                }
            }
            if (args.length > 1){
                proxiedServer = args[1];
            }
        }

        List<String> proxiedServerList = Arrays.asList(proxiedServer.split(";")) ;
        NettyHttpServer server = new NettyHttpServer(proxyPort,proxiedServerList);
        try {
            System.out.println(GATEWAY_NAME + " " + VERSION + " start..." );
            server.run();
            System.out.println(GATEWAY_NAME + " " + VERSION + " started at http://localhost:"+ proxyPort + " for server:" + server.toString() );
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
